import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';
import render from '@feidao/web/atom/browser/render/render';
import P04 from './P04';
import P05 from './P05';
import P07 from './P07';

export default async function a002(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	// 考试编号
	const exam_node = fd.data.node.querySelector<HTMLSpanElement>('[data-feidao-id="exam_id"]');
	const exam_id = exam_node.getAttribute('data-feidao-v');
	const criteria = { exam_id };
	// 列表查询
	const department_no = fd.data.node.querySelector<HTMLSelectElement>('[data-feidao-id="department"]').value;
	if (!department_no) {
		alert('请选择院部');
		return;
	}
	criteria['department_no'] = department_no;
	const major_no = fd.data.node.querySelector<HTMLSelectElement>('[data-feidao-id="major"]').value;
	if (!major_no) {
		alert('请选择专业');
		return;
	}
	criteria['major_no'] = major_no;
	const subject = fd.data.node.querySelector<HTMLSelectElement>('[data-feidao-id="subject"]').value;
	if (subject) {
		criteria['exam_subjects_name'] = { $regex: '.*' + subject + '.*', $options: 'i' };
	}
	const status = fd.data.node.querySelector<HTMLSelectElement>('[data-feidao-id="status"]').value;
	if (status) {
		criteria['is_arrange'] = status;
	}
	const data = await nodejs(fd.data.spaceid, 'exam_subjects_find', { criteria, page_size: 0, page_no: 1 });
	render(fd, data.dataArray, P04, 'P04', 'inner');
	// 清空考场数据
	render(fd, [], P05, 'P05', 'inner');
}
